package io.renren.modules.jsf.service.impl;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.jsf.dao.SubjectDao;
import io.renren.modules.jsf.entity.SubjectEntity;
import io.renren.modules.jsf.service.SubjectService;


@Service("subjectService")
public class SubjectServiceImpl extends ServiceImpl<SubjectDao, SubjectEntity> implements SubjectService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<SubjectEntity> page = null;
        String key = (String) params.get("key");
        if (StringUtils.isNotEmpty(key)) {
            page = this.page(
                    new Query<SubjectEntity>().getPage(params),
                    new QueryWrapper<SubjectEntity>().eq("subname", key)
            );
        } else {
            page = this.page(
                    new Query<SubjectEntity>().getPage(params),
                    new QueryWrapper<SubjectEntity>()
            );
        }
        return new PageUtils(page);
    }

    @Override
    public SubjectEntity selectByName(String coursename) {

        return baseMapper.selectOne(new QueryWrapper<SubjectEntity>().like("subname", coursename));
    }

    @Override
    public List<SubjectEntity> selectAll() {

        return baseMapper.selectList(null);
    }

}
